﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Class2HomeworkT1
{
    public partial class Form1 : Form
    {
        int i = 0;
        int numsOfArray;
        int[]a;
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (a == null)
            {
                textBox3.Text = "数组为空！";
            }
            else
            {
                int target = 0;
                for (int k = 0; k < numsOfArray; k++)
                {
                    target = target + a[k];
                }
                textBox3.Text = target.ToString();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (a == null)
            {
                textBox3.Text = "数组为空！";
            }
            else
            {
                int x = 0;
                int max = a[x];
                for (int k = 1; k < numsOfArray; k++)
                {
                    if (max < a[k])
                    {
                        max = a[k];
                    }
                }
                textBox3.Text = max.ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            numsOfArray = int.Parse(textBox1.Text);
            a = new int[numsOfArray];
            textBox1.Text = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            a[i] = int.Parse(textBox2.Text);
            i++;
            textBox2.Text = "";
            string str = "";
            for(int j=0;j<numsOfArray;j++)
            {
                str = str + a[j] + " ";
            }
            textBox4.Text = str;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            a = null;
            textBox4.Text = "";
            i = 0;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (a == null)
            {
                textBox3.Text = "数组为空！";
            }
            else
            {
                int x = 0;
                int min = a[x];
                for (int k = 1; k < numsOfArray; k++)
                {
                    if (min > a[k])
                    {
                        min = a[k];
                    }
                }
                textBox3.Text = min.ToString();
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (a == null)
            {
                textBox3.Text = "数组为空！";
            }
            else
            {
                float target = 0;
                for (int k = 0; k < numsOfArray; k++)
                {
                    target = target + a[k];
                }
                target = target / numsOfArray;
                textBox3.Text = target.ToString();
            }
        }
    }
}
